package nf.graph.persistence;

/**
 * Thrown on errors encountered while reading a graph.
 */
public class GraphReadException extends Exception
{
	private int lineNumber;

	public GraphReadException()
	{
		this(null);
	}

	public GraphReadException(String message)
	{
		this(message, 0);
	}
	
	public GraphReadException(String message, ParseException cause)
	{
		this(message, cause.getLineNumber(), cause);
	}
	
	GraphReadException(String message, Parser parser)
	{
		this(message, parser, null);
	}
	
		GraphReadException(String message, Parser parser, Throwable cause)
	{
		this(message, parser.getLineNumber(), cause);
	}

	public GraphReadException(String message, int lineNumber)
	{
		this(message, lineNumber, null);
	}

	public GraphReadException(String message, int lineNumber, Throwable cause)
	{
		super(message, cause);
		this.lineNumber = lineNumber;
	}

	public String toString()
	{
		if (lineNumber == 0)
			return super.toString();

		return String.format("%s on line %d: %s", getClass().getName(),
			lineNumber, getLocalizedMessage());
	}
}
